<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class mcategory extends MY_Model {

    var $theme_data = array(
        'layout_main' => 'layout',
        'left' => 'include/leftcp',
    );
    public $mytable = "category";
    public $primaryKey = "CAT_ID";
    public $resCode = "CATEGORY";

    function __construct() {
        parent::__construct();
    }

    function field() {
		$fieldData = array();
		$fieldData['CAT_NAME'] = '';
		$fieldData['CAT_CODE'] = '';
		$fieldData['CAT_DESCRIPTION'] = '';
		$fieldData['CAT_PARENT'] = 0;
		$fieldData['CAT_COUNT'] = 0;
		$fieldData['CAT_ORDER'] = 0;
		$fieldData['CAT_STATUS'] = 0;
		$fieldData['SEO_H1'] = '';
		$fieldData['SEO_DESCRIPTION'] = '';
		$fieldData['SEO_METATITLE'] = '';
		$fieldData['SEO_KEYWORD'] = '';
		$fieldData['CAT_COVER'] = '';
		$fieldData['CAT_THUMB'] = '';
		$fieldData['CAT_TIMEUPDATE'] = 0;
		$fieldData['CAT_TIMECREATE'] = 0;
		return $fieldData;
    }
	
	function gets_available() {
		$this->load->model('scache');
		$key = __CLASS__ ."_". __FUNCTION__;
		$cates = $this->scache->script($key, '$this->mcategory->gets(array("CAT_STATUS" => "1"));');
		return $cates;
	}
	
	function reload_cache(){
		$cates = $this->mcategory->gets();
		$data_temp =array();
		$data = "<?php \n";
        $data.="return ";
		if($cates) {
			foreach($cates as $cate){
			if($cate->CAT_CODE != '')
				$data_temp[] = strtolower($cate->CAT_CODE);
			}
		$data_temp = var_export($data_temp, true);
		$data.= $data_temp;
        $data.="?>\n";
        write_file('./mcache/category_router.php', $data);
		}
	}
}

?>